package com.shaoshaohuo.app.ui;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.shaoshaohuo.app.BigbitmapUtils;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.constant.ShareKey;
import com.shaoshaohuo.app.entity.DetailsEntity;
import com.shaoshaohuo.app.entity.FragmentNewCarEntity;
import com.shaoshaohuo.app.framework.SharedPreferencesHelper;
import com.shaoshaohuo.app.net.HttpConfig;
import com.shaoshaohuo.app.net.NewHttpCofig;
import com.shaoshaohuo.app.net.RequestParam;
import com.shaoshaohuo.app.net.ShopHttpConfig;
import com.shaoshaohuo.app.utils.CircleImageView;
import com.shaoshaohuo.app.utils.FiveCornerStar;
import com.shaoshaohuo.app.utils.LoginUtils;
import com.shaoshaohuo.app.utils.Okhttputils;
import com.shaoshaohuo.app.utils.sharesdk.ShareContent;
import com.shaoshaohuo.app.view.DeleteTextView;
import com.shaoshaohuo.app.view.NumberView;
import com.shaoshaohuo.app.view.SelfadaptionImageview;
import com.shaoshaohuo.app.view.ShareDialog;
import com.shaoshaohuo.app.view.Vpindicator;
import com.squareup.picasso.Picasso;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.sharesdk.framework.Platform;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 新详情页
 * Created by Administrator on 2017/7/5.
 */

public class NewDetailsActivity extends BaseActivity implements View.OnClickListener {
    private String catid;
    private List<View> views;
    private TextView fragment_detatop_tv_nmae;
    private TextView fragment_detatop_tv_guige;
    private TextView fragment_detatop_tv_danjian;
    private TextView fragment_detatop_tv_detalis;
    private TextView fragment_detatop_tv_money;
    private DeleteTextView fragment_detatop_tv_shopmoney;
    private NumberView deatils_numberView;
    private Button fragment_detalis_top_btn_add;
    private Button fragment_detalis_top_btn_gm;
    private ViewPager viewPager;
    private TextView pj_user_value;
    private TextView bcd;
    private TextView pj_user_num;
    private CircleImageView pj_user_photo;
    private Handler handler = new Handler();
    private DetailsEntity detailsEntity;
    private TextView fragment_detatop_iv_sc;
    private LinearLayout fragment_detalis_bottom_lin;
    private TextView fragment_detalis_bottom_psfw;
    private TextView tv_pinm;
    private TextView fragment_detalis_bottom_cd;
    private TextView fragment_detalis_bottom_yyjz;
    private TextView tv_waiguan;
    private TextView tv_kougan;
    private TextView tv_baozhuang;
    private TextView teji_danguo;
    private TextView teji_guige;
    private TextView yiji_danguo;
    private TextView yi_guige;
    private TextView erji_danguo;
    private TextView erji_guige;
    private TextView sanji_danguo;
    private TextView sanji_guige;
    private TextView fragment_detatop_tv_levle;
    private Vpindicator vpd;
    private TextView tv_jianmoney;
    private LinearLayout fragment_detalis_advertImg_lin;
    private String imaurl;

    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_nd_layout);
        ViewGroup content = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
        View childAt = content.getChildAt(0);
        changeTransltestaus(this, childAt, TransltestausModel.NoePicter, Color.parseColor("#B2000000"));
        Intent intent = getIntent();
        catid = intent.getStringExtra(ShareKey.CATID);
        imaurl = intent.getStringExtra("imgurl");
        vpd = (Vpindicator) findViewById(R.id.vpd);
        View viewById = findViewById(R.id.detalisActivity_relatopbar);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) viewById.getLayoutParams();
            layoutParams.setMargins(0, getStatusBarHeight(this), 0, 0);
        }
        init();
        initbottm();
        network();
    }

    @Override
    protected void onResume() {
        super.onResume();
        boolean aBoolean = SharedPreferencesHelper.getBoolean(this, SharedPreferencesHelper.Field.HOME, false);
        if (aBoolean) {
            finish();
        }
    }

    private void initbottm() {

        fragment_detalis_bottom_lin = (LinearLayout) findViewById(R.id.fragment_detalis_bottom_lin);


        fragment_detalis_bottom_psfw = (TextView) findViewById(R.id.fragment_detalis_bottom_psfw);

        fragment_detalis_bottom_cd = (TextView) findViewById(R.id.fragment_detalis_bottom_cd);

        fragment_detalis_bottom_yyjz = (TextView) findViewById(R.id.fragment_detalis_bottom_yyjz);

        GridLayout viewById = (GridLayout) findViewById(R.id.grd);

        for (int i = 0; i < viewById.getChildCount(); i++) {
            View childAt = viewById.getChildAt(i);
            GridLayout.LayoutParams layoutParams = (GridLayout.LayoutParams) childAt.getLayoutParams();
            layoutParams.width = getResources().getDisplayMetrics().widthPixels / 5;
            childAt.setLayoutParams(layoutParams);
        }

        tv_pinm = (TextView) findViewById(R.id.tv_pinm);
        fragment_detalis_advertImg_lin = (LinearLayout) findViewById(R.id.fragment_detalis_advertImg_lin);
        //表格
        tv_waiguan = (TextView) findViewById(R.id.tv_waiguan);

        tv_kougan = (TextView) findViewById(R.id.tv_kougan);

        tv_baozhuang = (TextView) findViewById(R.id.tv_baozhuang);

        //特級
        teji_danguo = (TextView) findViewById(R.id.teji_danguo);

        teji_guige = (TextView) findViewById(R.id.teji_guige);
        //一级
        yiji_danguo = (TextView) findViewById(R.id.yiji_danguo);
        yi_guige = (TextView) findViewById(R.id.yi_guige);
        //二級
        erji_danguo = (TextView) findViewById(R.id.erji_danguo);
        erji_guige = (TextView) findViewById(R.id.erji_guige);
        //三級
        sanji_danguo = (TextView) findViewById(R.id.sanji_danguo);
        sanji_guige = (TextView) findViewById(R.id.sanji_guige);
        findViewById(R.id.pj_user_all).setOnClickListener(this);
    }

    private void network() {
        //解析
        Map<String, String> headerParams = RequestParam.getHeaderParams();
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("catid", catid);
        Okhttputils.Instanse(this).postFromBody(headerParams, HttpConfig.BASE_HOST_URL + NewHttpCofig.App_Details, stringStringHashMap, new Okhttputils.OkutListener() {
            @Override
            public void error(Call call, IOException e) {

            }

            @Override
            public void error(Call call, int code) {

            }

            @Override
            public void suseff(Call call, Response response, Object o) {
                detailsEntity = (DetailsEntity) o;
                final DetailsEntity.DataBean data = detailsEntity.getData();
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        String name = data.getName();
                        String level = data.getLevel();
                        fragment_detatop_tv_levle.setText(level);
                        fragment_detatop_tv_nmae.setText(name);
                        String mbn_details = data.getMbn_details();
                        if (data.getMbn_detailsType().equals("1")) {
                            fragment_detatop_tv_guige.setText("约" + mbn_details + "斤/件");
                        }
                        if (data.getMbn_detailsType().equals("2")) {
                            fragment_detatop_tv_guige.setText("约" + mbn_details + "个/件");
                        }
                        String details = data.getDetails();
                        fragment_detatop_tv_danjian.setText(details + ")");
                        //taste_details
                        String taste_details = data.getTaste_details();
                        fragment_detatop_tv_detalis.setText(taste_details);
                        String money = data.getMoney();

                        String shop_money = data.getShop_money();
                        fragment_detatop_tv_shopmoney.setText(shop_money);
                        String mbn_detailsType = data.getMbn_detailsType();
                        if (mbn_detailsType.equals("1")) {
                            fragment_detatop_tv_money.setText("共享价:¥" + money + "/斤");
                            fragment_detatop_tv_shopmoney.setText(shop_money + "/斤");
                        } else {
                            fragment_detatop_tv_money.setText("共享价:¥" + money + "/个");
                            fragment_detatop_tv_shopmoney.setText(shop_money + "/个");
                        }
                        int carNum = data.getCarNum();
                        if (carNum <= 0) {
                            deatils_numberView.setVisibility(View.GONE);
                        } else {
                            deatils_numberView.setVisibility(View.VISIBLE);
                        }
                        deatils_numberView.setNum(carNum + "");
                        List<DetailsEntity.DataBean.ImgMapBean> img_map = detailsEntity.getData().getImg_map();
                        views = new ArrayList<View>();
                        for (int i = 0; i < img_map.size(); i++) {
                            ImageView imageView = new ImageView(NewDetailsActivity.this);
                            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                            Picasso.with(NewDetailsActivity.this).load(img_map.get(i).getImg()).placeholder(R.mipmap.zhanzhanzhan).into(imageView);
                            views.add(imageView);
                        }

                        ViewGroup.LayoutParams layoutParams = fragment_detalis_bottom_lin.getLayoutParams();
                        layoutParams.height = (int) (fragment_detalis_bottom_lin.getPaddingBottom() + data.getHeight() * ((float) getResources().getDisplayMetrics().widthPixels / (float) data.getWidth()));
//                        fragment_detalis_advertImg_linetAdvertImg().size(); i++) {
                        for (int i = 0; i < data.getAdvertImg().size(); i++) {
                            SelfadaptionImageview imageView = new SelfadaptionImageview(NewDetailsActivity.this);

                            fragment_detalis_advertImg_lin.addView(imageView);
                            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                            Picasso.with(NewDetailsActivity.this).load(data.getAdvertImg().get(i)).placeholder(R.mipmap.zhanzhanzhan).into(imageView);
                        }


                        double m = Double.valueOf(data.getMoney()) * Double.valueOf(data.getMbn_details());
                        BigDecimal b = new BigDecimal(m);
                        float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
                        tv_jianmoney.setText("￥" + f1 + "/件");
                        float dimension = getResources().getDimension(R.dimen.imamarn1);
                        viewPager.setAdapter(new MyvpAdapter());
                        vpd.setvp(viewPager);
                        vpd.setnum(BitmapFactory.decodeResource(getResources(), R.mipmap.rectangle_normal), BitmapFactory.decodeResource(getResources(), R.mipmap.rectangle_unusual), views.size(), (int) dimension);
                        List<DetailsEntity.DataBean.RemarkBean> a = data.getRemark();
                        if (a.size() > 0) {
                            FiveCornerStar pj_user_xx = (FiveCornerStar) findViewById(R.id.pj_user_xx);
                            pj_user_xx.setIsdown(false);
                            pj_user_xx.setNum(5, BitmapFactory.decodeResource(getResources(), R.mipmap.star).getWidth(), BitmapFactory.decodeResource(getResources(), R.mipmap.star).getHeight());
                            pj_user_xx.setdownnum(Float.parseFloat(data.getRemark().get(0).getRemarkLevel()));
                            DetailsEntity.DataBean.RemarkBean remark = a.get(0);
                            TextView pj_user_phonenum = (TextView) findViewById(R.id.pj_user_phonenum);

                            String userPhone = remark.getUserPhone();
                            if (userPhone != null && userPhone.length() > 7) {
                                String substring = userPhone.substring(3, 7);
                                String replace = userPhone.replace(substring, "****");
                                pj_user_phonenum.setText(replace);
                            }


                            bcd = (TextView) findViewById(R.id.bcd);
                            String remarkPen = remark.getRemarkPen();
                            bcd.setText(remarkPen);
                            pj_user_num = (TextView) findViewById(R.id.pj_user_num);
                            int remarkNum = remark.getRemarkNum();
                            pj_user_num.setText(remarkNum + "");
                            pj_user_photo = (CircleImageView) findViewById(R.id.pj_user_photo);
                            if (remark.getUserImg().length() > 0) {
                                Picasso.with(NewDetailsActivity.this).load(remark.getUserImg()).placeholder(R.mipmap.zhanzhanzhan).into(pj_user_photo);
                            }
                            String remarkValue = remark.getRemarkValue();
                            pj_user_value.setText(remarkValue);
                        } else {
                            findViewById(R.id.pj_1).setVisibility(View.GONE);
                            findViewById(R.id.pj_2).setVisibility(View.GONE);
                            pj_user_value.setText("暂无评论");
                        }
                        //bottom
                        String img_details = detailsEntity.getData().getImg_details();
                        if (img_details != null && img_details.length() > 0) {
                            BigbitmapUtils.BigImage(img_details, NewDetailsActivity.this, fragment_detalis_bottom_lin);
                        }
                        String scope = detailsEntity.getData().getScope();
                        String homeland = detailsEntity.getData().getHomeland();
                        fragment_detalis_bottom_psfw.setText(scope);
                        fragment_detalis_bottom_cd.setText(homeland);
                        tv_pinm.setText("品名：" + name);
                        tv_waiguan.setText(detailsEntity.getData().getOutlook());
                        tv_kougan.setText(detailsEntity.getData().getTaste_details());
                        tv_baozhuang.setText(detailsEntity.getData().getMbn_details() + "");
                        yiji_danguo.setText(detailsEntity.getData().getOneStand());
                        teji_danguo.setText(detailsEntity.getData().getSuperStand());
                        yi_guige.setText(detailsEntity.getData().getOneDetail());
                        erji_danguo.setText(detailsEntity.getData().getTwoStand());
                        teji_guige.setText(detailsEntity.getData().getSuperDetail());
                        erji_guige.setText(detailsEntity.getData().getTwoDetail());
                        sanji_danguo.setText(detailsEntity.getData().getThreeStand());
                        sanji_guige.setText(detailsEntity.getData().getThreeDetail());
                        tv_baozhuang.setText(detailsEntity.getData().getMbn_details() + "");

                        yiji_danguo.setText(detailsEntity.getData().getOneDetail());
                        teji_danguo.setText(detailsEntity.getData().getSuperDetail());
                        erji_danguo.setText(detailsEntity.getData().getTwoDetail());
                        sanji_danguo.setText(detailsEntity.getData().getThreeDetail());
                        //
                        teji_guige.setText(detailsEntity.getData().getSuperStand());
//                        /
                        erji_guige.setText(detailsEntity.getData().getTwoStand());
                        //
                        yi_guige.setText(detailsEntity.getData().getOneStand());
                        //
                        sanji_guige.setText(detailsEntity.getData().getThreeStand());
                        fragment_detalis_bottom_yyjz.setText(detailsEntity.getData().getWork());
                    }

                });

            }
        }, DetailsEntity.class);
    }

    private void init() {
        ImageView detalisActivity_back = (ImageView) findViewById(R.id.detalisActivity_back);
        detalisActivity_back.setOnClickListener(this);
        ImageView detalisActivity_share = (ImageView) findViewById(R.id.detalisActivity_share);
        detalisActivity_share.setOnClickListener(this);
        //=========================================================================//
        Button fragment_detalis_top_btn_add = (Button) findViewById(R.id.fragment_detalis_top_btn_add);
        fragment_detalis_top_btn_add.setOnClickListener(this);
        fragment_detatop_tv_nmae = (TextView) findViewById(R.id.fragment_detatop_tv_nmae);
        fragment_detatop_tv_levle = (TextView) findViewById(R.id.fragment_detatop_tv_levle);
        fragment_detatop_tv_guige = (TextView) findViewById(R.id.fragment_detatop_tv_guige);


        fragment_detatop_tv_danjian = (TextView) findViewById(R.id.fragment_detatop_tv_danjian);

        fragment_detatop_tv_detalis = (TextView) findViewById(R.id.fragment_detatop_tv_detalis);

        fragment_detatop_tv_money = (TextView) findViewById(R.id.fragment_detatop_tv_money);

        fragment_detatop_tv_shopmoney = (DeleteTextView) findViewById(R.id.fragment_detatop_tv_shopmoney);

        deatils_numberView = (NumberView) findViewById(R.id.deatils_numberView);

        fragment_detalis_top_btn_add = (Button) findViewById(R.id.fragment_detalis_top_btn_add);
        fragment_detalis_top_btn_add.setOnClickListener(this);
        fragment_detalis_top_btn_gm = (Button) findViewById(R.id.fragment_detalis_top_btn_gm);
        fragment_detalis_top_btn_gm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (LoginUtils.IsLogining()) {


                    if (detailsEntity != null) {
                        FragmentNewCarEntity fragmentNewCarEntity = new FragmentNewCarEntity();
                        DetailsEntity.DataBean data = detailsEntity.getData();
                        fragmentNewCarEntity.setData(new ArrayList<FragmentNewCarEntity.DataBean>());
                        List<FragmentNewCarEntity.DataBean> data1 = fragmentNewCarEntity.getData();
                        FragmentNewCarEntity.DataBean dataBean = new FragmentNewCarEntity.DataBean();
                        dataBean.setNum(data.getCarNum() + "");
                        dataBean.setCatid(data.getCatid());
                        dataBean.setDetails(data.getDetails());
                        dataBean.setImg(data.getImg());
                        dataBean.setNames(data.getName());
                        dataBean.setMbn_details(Integer.valueOf(data.getMbn_details()));
                        dataBean.setPrice(data.getMoney());
                        dataBean.setShop_price(data.getShop_money());
                        dataBean.setMbn_detailsType(Integer.valueOf(data.getMbn_detailsType()));
                        data1.add(dataBean);
                        Intent intent = new Intent();
                        intent.setClass(NewDetailsActivity.this, SureOrderPayInformation.class);
                        intent.putExtra("fragmentNewCarEntity", fragmentNewCarEntity);
                        intent.putExtra("gotype", "2");//单个到订单
                        intent.putExtra("sorttype", "1");//普通商品
                        startActivity(intent);
                    } else {
                        Toast.makeText(NewDetailsActivity.this, "您的网络飞啦~~~", Toast.LENGTH_LONG).show();
                    }
                } else {
                    startActivity(intentLogin());
                }
            }
        });

        viewPager = (ViewPager) findViewById(R.id.fragment_detatop_vp);


        RelativeLayout fragment_detatop_lin_gw = (RelativeLayout) findViewById(R.id.fragment_detatop_lin_gw);
        fragment_detatop_lin_gw.setOnClickListener(this);
        viewPager.getLayoutParams().height = getResources().getDisplayMetrics().heightPixels * 2 / 3 - fragment_detatop_lin_gw.getLayoutParams().height;
        RelativeLayout fragment_detatop_lin_sc = (RelativeLayout) findViewById(R.id.fragment_detatop_lin_sc);
        fragment_detatop_iv_sc = (TextView) findViewById(R.id.fragment_detatop_iv_sc);
        fragment_detatop_lin_sc.getChildAt(0);
        tv_jianmoney = (TextView) findViewById(R.id.tv_jianmoney);
        /**
         * 评论相关
         */

        pj_user_value = (TextView) findViewById(R.id.pj_user_value);
        fragment_detatop_lin_sc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                if (LoginUtils.IsLogining()) {
                    if (detailsEntity != null) {
                        View childAt = ((RelativeLayout) v).getChildAt(0);
                        if (childAt.isSelected()) {
                            ShopHttpConfig.Collectiondelte(NewDetailsActivity.this, detailsEntity.getData().getCatid(), new Okhttputils.OkutListener() {
                                @Override
                                public void error(Call call, IOException e) {

                                }

                                @Override
                                public void error(Call call, int code) {

                                }

                                @Override
                                public void suseff(Call call, Response response, Object o) {
                                    v.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            View childAt = ((RelativeLayout) v).getChildAt(0);
                                            fragment_detatop_iv_sc.setSelected(false);
                                        }
                                    });
                                }
                            });
                        } else {
                            ShopHttpConfig.Collectionadd(NewDetailsActivity.this, detailsEntity.getData().getCatid(), new Okhttputils.OkutListener() {
                                @Override
                                public void error(Call call, IOException e) {

                                }

                                @Override
                                public void error(Call call, int code) {

                                }

                                @Override
                                public void suseff(Call call, Response response, Object o) {
                                    v.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            Log.e("TAG", "run: ===========");
                                            View childAt = ((RelativeLayout) v).getChildAt(0);
                                            fragment_detatop_iv_sc.setSelected(true);
                                        }
                                    });

                                }
                            });
                        }
                    } else {
                        Toast.makeText(NewDetailsActivity.this, "您的网络飞啦~~~", Toast.LENGTH_LONG).show();
                    }


                } else {
                    startActivity(intentLogin());
                }
            }
        });

    }

    private Intent intentLogin() {
        Intent intent = new Intent();
        intent.setClass(getApplicationContext(), LoginActivity.class);
        return intent;
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.detalisActivity_share:

                ShareDialog shareDialog = new ShareDialog(v.getContext());
                Platform.ShareParams shareParams = new Platform.ShareParams();
                shareParams.setTitle("妈妈爱果");
                shareParams.setTitleUrl(HttpConfig.BASE_HOST_URL + NewHttpCofig.Share + "?catid=" + catid);
                shareParams.setText(ShareContent.SHARE_APP_CONTENT);
                shareParams.setImageUrl(imaurl);
                shareParams.setUrl(HttpConfig.BASE_HOST_URL + NewHttpCofig.Share + "?catid=" + catid);
                shareDialog.setshareParams(shareParams);
                shareDialog.show();


//                    ShareDialog shareDialog = new ShareDialog(v.getContext());
//                    Platform.ShareParams shareParams = new Platform.ShareParams();
//                    shareParams.setTitle("妈妈爱果");
//                    shareParams.setTitleUrl(HttpConfig.BASE_HOST_URL + NewHttpCofig.Share + "?catid=" + catid);
//                    shareParams.setText(ShareContent.SHARE_APP_CONTENT);
//                    shareParams.setImageUrl(imaurl);
//                    shareParams.setUrl(HttpConfig.BASE_HOST_URL + NewHttpCofig.Share + "?catid=" + catid);
//                    shareDialog.setshareParams(shareParams);
//                    shareDialog.show();
                break;

            case R.id.detalisActivity_back:
                finish();
                break;
            case R.id.fragment_detalis_top_btn_add:
                //添加购物车
                if (LoginUtils.IsLogining()) {
                    if (detailsEntity != null) {
                        ShopHttpConfig.addshop(this, detailsEntity.getData().getCatid(), new Okhttputils.OkutListener() {
                            @Override
                            public void error(Call call, IOException e) {

                            }

                            @Override
                            public void error(Call call, int code) {

                            }

                            @Override
                            public void suseff(Call call, Response response, Object o) {
                                deatils_numberView.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        deatils_numberView.setVisibility(View.VISIBLE);
                                        deatils_numberView.setNum((deatils_numberView.getnum() + 1) + "");
                                        detailsEntity.getData().setCarNum(deatils_numberView.getnum());
                                    }
                                });
                            }
                        });
                    } else {
                        Toast.makeText(NewDetailsActivity.this, "您的网络飞啦~~~", Toast.LENGTH_LONG).show();
                    }
                } else {
                    startActivity(intentLogin());
                }
                break;
            case R.id.fragment_detatop_lin_gw:
                if (LoginUtils.IsLogining()) {
                    Toast.makeText(NewDetailsActivity.this, "购物车页面~~~", Toast.LENGTH_LONG).show();
                    Intent intent1 = new Intent(this, PjActivity.class);
                    intent1.putExtra("type", "1");
                    startActivity(intent1);
                } else {
                    startActivity(intentLogin());
                }
                break;
            case R.id.pj_user_all:
                Intent intent = new Intent(this, PjTowActivity.class);
                intent.putExtra("catid", catid);
                startActivity(intent);
                break;
        }

    }

    class MyvpAdapter extends PagerAdapter {
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View view = views.get(position);
            container.addView(view);
            return view;

        }

        @Override
        public int getCount() {
            return views.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object o) {
            return view == o;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
//            super.destroyItem(container, position, object);
            container.removeView(views.get(position));
        }
    }
}
